<?php
/**
 *Data Base Category
 *
 *Class for manager the category, is extends of DBClass
 *
 *@author Alberto Berroteran <ashrey10@yahoo.es>
 *@version 0.1 Beta
 *@copyright Copyrigth (c)2008 Alberto Berroteran
 */
final class Tag extends ARecord{
	function toindex($b_only = false){
		$o_db = new dbARecord($this->o_connect);
		$o_db->tables('tag')->cols('id_tag', 'name')->order('name');
		return $o_db->select();
	}

	function getTags(){
		$this->cols('tagpost.id_tag' , 'name', 'count(*) as total');
		$this->tables('tag', 'tagpost')->groupBy('name')->order('total DESC');
		$this->where('%1$stagpost.id_tag = %1$stag.id_tag', AB_TABLE_PREFIX);
		return $this->select();
	}

	function getPosts($s_name){
		$this->cols('tagpost.id_tag', 'name', 'title', 'content', 'modified')->tables('tag', 'tagpost', 'post');
		$this->where('name = "%2$s" AND %1$stagpost.id_tag = %1$stag.id_tag AND %1$stagpost.id_post = %1$spost.id_post', AB_TABLE_PREFIX, $s_name);
		return $this->select();
	}
}
?>
